import {
    Observable,
    of,
    from,
    throwError,
} from 'rxjs'

// 创建操作符，用来创建Observable的操作符

// 1.of 创建操作符，用来创建发出特定值得Observable
const observable = of(1, 2, 3)
observable.subscribe(console.log)

console.log('-----------------------')
// 2. from 创建操作符，可以将数组，promise或迭代器转为Observable
const observable_form = from([1, 2, 3])
observable_form.subscribe(console.log)
console.log('--------------')
const observable_form2 = from(Promise.resolve(2))
observable_form2.subscribe(console.log)


console.log('-----------------------')
// 3. throwError 是一个创建操作符，用来创建一个立即发出错误的Observable
const observable_throwError = throwError(() => new Error('an error occurred'));
// 类似于try catch捕获
observable_throwError.subscribe({
    next: console.log,
    error: err => console.log(err.message),
})
